<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入公司名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料号" prop="materialNumber">
        <el-input
          v-model="queryParams.materialNumber"
          placeholder="请输入物料号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格型号" prop="specification">
        <el-input
          v-model="queryParams.specification"
          placeholder="请输入规格型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制造商名称" prop="manufacturerName">
        <el-input
          v-model="queryParams.manufacturerName"
          placeholder="请输入制造商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报价编号" prop="quoteNumber">
        <el-input
          v-model="queryParams.quoteNumber"
          placeholder="请输入报价编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['sales:ZcQuotationOverview:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['sales:ZcQuotationOverview:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['sales:ZcQuotationOverview:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sales:ZcQuotationOverview:export']"
        >导出</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--            type="info"-->
<!--            plain-->
<!--            icon="el-icon-upload2"-->
<!--            size="mini"-->
<!--            @click="handleImport"-->
<!--        >导入</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ZcQuotationOverviewList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司名称" align="center" prop="companyName" />
      <el-table-column label="公司代码" align="center" prop="companyCode" />
      <el-table-column label="发布日期" align="center" prop="publishDate" width="180"/>
      <el-table-column label="报价结束日期" align="center" prop="quoteEndDate" width="180"/>
      <el-table-column label="开标日期" align="center" prop="bidDate" width="180"/>
      <el-table-column label="订单类型" align="center" prop="orderType" />
      <el-table-column label="订单编号" align="center" prop="orderNumber" />
      <el-table-column label="物料类型" align="center" prop="materialType" />
      <el-table-column label="物料名称" align="center" prop="materialName" />
      <el-table-column label="物料号" align="center" prop="materialNumber" />
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="物料单位" align="center" prop="materialUnit" />
      <el-table-column label="条形码" align="center" prop="barcode" />
      <el-table-column label="制造商编码" align="center" prop="manufacturerCode" />
      <el-table-column label="制造商名称" align="center" prop="manufacturerName" />
      <el-table-column label="采购数量" align="center" prop="purchaseQuantity" />
      <el-table-column label="交货日期" align="center" prop="deliveryDate" width="180"/>
      <el-table-column label="交货地址" align="center" prop="deliveryAddress" />
      <el-table-column label="运费" align="center" prop="freight" />
      <el-table-column label="尺寸" align="center" prop="size" />
      <el-table-column label="单重" align="center" prop="unitWeight" />
      <el-table-column label="总重" align="center" prop="totalWeight" />
      <el-table-column label="颜色" align="center" prop="color" />
      <el-table-column label="花纹" align="center" prop="pattern" />
      <el-table-column label="材质" align="center" prop="materialMaterial" />
      <el-table-column label="包装数量" align="center" prop="packagingQuantity" />
      <el-table-column label="包装尺寸" align="center" prop="packagingSize" />
      <el-table-column label="包装材质" align="center" prop="packagingMaterial" />
      <el-table-column label="采购人" align="center" prop="purchaser" />
      <el-table-column label="报价编号" align="center" prop="quoteNumber" />
      <el-table-column label="报价日期" align="center" prop="quoteDate" width="180"/>
      <el-table-column label="确认日期" align="center" prop="confirmationDate" width="180"/>
      <el-table-column label="报价" align="center" prop="quoteExclTax" />
      <el-table-column label="税率" align="center" prop="taxRate" />
      <el-table-column label="报价" align="center" prop="quoteInclTax" />
      <el-table-column label="报价单位" align="center" prop="quoteUnit" />
      <el-table-column label="报价人" align="center" prop="quotePerson" />
      <el-table-column label="审核日期" align="center" prop="auditDate" width="180"/>
      <el-table-column label="审核人" align="center" prop="auditor" />
      <el-table-column label="招采状态" align="center" prop="procurementStatus" />
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleConfirm(scope.row)"
            :disabled="scope.row.confirmStatus!='0'"
          >中标
          </el-button>
<!--          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sales:ZcQuotationOverview:edit']"
          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['sales:ZcQuotationOverview:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改报价一览对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="公司名称" prop="companyName">
              <el-input v-model="form.companyName" placeholder="请输入公司名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司代码" prop="companyCode">
              <el-input v-model="form.companyCode" placeholder="请输入公司代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发布日期" prop="publishDate">
              <el-date-picker clearable
                v-model="form.publishDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择发布日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报价结束日期" prop="quoteEndDate">
              <el-date-picker clearable
                v-model="form.quoteEndDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择报价结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开标日期" prop="bidDate">
              <el-date-picker clearable
                v-model="form.bidDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择开标日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单编号" prop="orderNumber">
              <el-input v-model="form.orderNumber" placeholder="请输入订单编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料名称" prop="materialName">
              <el-input v-model="form.materialName" placeholder="请输入物料名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料号" prop="materialNumber">
              <el-input v-model="form.materialNumber" placeholder="请输入物料号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="规格型号" prop="specification">
              <el-input v-model="form.specification" placeholder="请输入规格型号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料单位" prop="materialUnit">
              <el-input v-model="form.materialUnit" placeholder="请输入物料单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="条形码" prop="barcode">
              <el-input v-model="form.barcode" placeholder="请输入条形码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="制造商编码" prop="manufacturerCode">
              <el-input v-model="form.manufacturerCode" placeholder="请输入制造商编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="制造商名称" prop="manufacturerName">
              <el-input v-model="form.manufacturerName" placeholder="请输入制造商名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="采购数量" prop="purchaseQuantity">
              <el-input v-model="form.purchaseQuantity" placeholder="请输入采购数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交货日期" prop="deliveryDate">
              <el-date-picker clearable
                v-model="form.deliveryDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择交货日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交货地址" prop="deliveryAddress">
              <el-input v-model="form.deliveryAddress" placeholder="请输入交货地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="运费" prop="freight">
              <el-input v-model="form.freight" placeholder="请输入运费" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="尺寸" prop="size">
              <el-input v-model="form.size" placeholder="请输入尺寸" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单重" prop="unitWeight">
              <el-input v-model="form.unitWeight" placeholder="请输入单重" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总重" prop="totalWeight">
              <el-input v-model="form.totalWeight" placeholder="请输入总重" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="颜色" prop="color">
              <el-input v-model="form.color" placeholder="请输入颜色" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="花纹" prop="pattern">
              <el-input v-model="form.pattern" placeholder="请输入花纹" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="材质" prop="materialMaterial">
              <el-input v-model="form.materialMaterial" placeholder="请输入材质" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装数量" prop="packagingQuantity">
              <el-input v-model="form.packagingQuantity" placeholder="请输入包装数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装尺寸" prop="packagingSize">
              <el-input v-model="form.packagingSize" placeholder="请输入包装尺寸" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装材质" prop="packagingMaterial">
              <el-input v-model="form.packagingMaterial" placeholder="请输入包装材质" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="采购人" prop="purchaser">
              <el-input v-model="form.purchaser" placeholder="请输入采购人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报价编号" prop="quoteNumber">
              <el-input v-model="form.quoteNumber" placeholder="请输入报价编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报价日期" prop="quoteDate">
              <el-date-picker clearable
                v-model="form.quoteDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择报价日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="确认日期" prop="confirmationDate">
              <el-date-picker clearable
                v-model="form.confirmationDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择确认日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报价" prop="quoteExclTax">
              <el-input v-model="form.quoteExclTax" placeholder="请输入报价" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="税率" prop="taxRate">
              <el-input v-model="form.taxRate" placeholder="请输入税率" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报价" prop="quoteInclTax">
              <el-input v-model="form.quoteInclTax" placeholder="请输入报价" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报价单位" prop="quoteUnit">
              <el-input v-model="form.quoteUnit" placeholder="请输入报价单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报价人" prop="quotePerson">
              <el-input v-model="form.quotePerson" placeholder="请输入报价人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核日期" prop="auditDate">
              <el-date-picker clearable
                v-model="form.auditDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择审核日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核人" prop="auditor">
              <el-input v-model="form.auditor" placeholder="请输入审核人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报价单附件" prop="quoteAttachment">
              <el-input v-model="form.quoteAttachment" placeholder="请输入报价单附件" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url + '?updateSupport=' + upload.updateSupport"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--  <div class="el-upload__tip" slot="tip">
              <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
            </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { confirmZcQuotationOverview,listZcQuotationOverview, getZcQuotationOverview, delZcQuotationOverview, addZcQuotationOverview, updateZcQuotationOverview } from "@/api/sales/ZcQuotationOverview";
import {getToken} from "@/utils/auth";
export default {
  name: "ZcQuotationOverview",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报价一览表格数据
      ZcQuotationOverviewList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: null,
        orderType: null,
        orderNumber: null,
        materialType: null,
        materialName: null,
        materialNumber: null,
        specification: null,
        manufacturerName: null,
        quoteNumber: null,
      },
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "导入`ZcQuotationOverview`信息",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/sales/ZcQuotationOverview/importData"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleConfirm(row){
      this.$modal.confirm('是否确认此报价？').then(function() {
        return confirmZcQuotationOverview(row);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("确认成功");
      }).catch(() => {});
    },
    /** 查询报价一览列表 */
    getList() {
      this.loading = true;
      listZcQuotationOverview(this.queryParams).then(response => {
        this.ZcQuotationOverviewList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyName: null,
        companyCode: null,
        publishDate: null,
        quoteEndDate: null,
        bidDate: null,
        orderType: null,
        orderNumber: null,
        materialType: null,
        materialName: null,
        materialNumber: null,
        specification: null,
        materialUnit: null,
        barcode: null,
        manufacturerCode: null,
        manufacturerName: null,
        purchaseQuantity: null,
        deliveryDate: null,
        deliveryAddress: null,
        freight: null,
        size: null,
        unitWeight: null,
        totalWeight: null,
        color: null,
        pattern: null,
        materialMaterial: null,
        packagingQuantity: null,
        packagingSize: null,
        packagingMaterial: null,
        purchaser: null,
        quoteNumber: null,
        quoteDate: null,
        confirmationDate: null,
        quoteExclTax: null,
        taxRate: null,
        quoteInclTax: null,
        quoteUnit: null,
        quotePerson: null,
        auditDate: null,
        auditor: null,
        quoteAttachment: null,
        procurementStatus: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报价一览";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getZcQuotationOverview(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报价一览";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateZcQuotationOverview(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZcQuotationOverview(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据？').then(function() {
        return delZcQuotationOverview(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sales/ZcQuotationOverview/export', {
        ...this.queryParams
      }, `ZcQuotationOverview_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "报价一览导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('sales/ZcQuotationOverview/importTemplate', {
      }, `报价一览模板.xlsx`)
    },
    /** 文件上传中处理 */
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    /** 文件上传成功处理 */
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    /** 提交上传文件 */
    submitFileForm() {
      this.$refs.upload.submit();
    },
  }
};
</script>
